/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package shipwright.controls;

import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.input.InputManager;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.math.Vector3f;

/**
 *
 * @author root
 */
public class BoatControl implements AnalogListener {
    
    private RigidBodyControl body,body2;
    private BulletAppState bulletAppState;
    
    public BoatControl(RigidBodyControl body,RigidBodyControl body2, BulletAppState bas, InputManager inputManager){
        this.body = body;
        this.body2 = body2;
        this.bulletAppState = bas;
        inputManager.addMapping("Rise", new KeyTrigger(KeyInput.KEY_U));
        inputManager.addMapping("Up", new KeyTrigger(KeyInput.KEY_I));
        inputManager.addMapping("Down", new KeyTrigger(KeyInput.KEY_K));
        inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_L));
        inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_J));

        inputManager.addListener(this, "Left", "Up", "Right", "Down", "Rise");
    }
    

    
     public void onAnalog(String name, float value, float tpf) {
            if (name.equals("Rise")) {
                //brick_phy.setLinearVelocity(new Vector3f(0f,5f,0f));
                body.applyCentralForce(new Vector3f(0, (float) 5f, 0));
                System.out.println(value);
                bulletAppState.update(tpf);
            }
            if (name.equals("Left")) {
                body.applyForce(new Vector3f(.5f, 0, 0), new Vector3f(-.5f, .5f, 0));
                bulletAppState.update(tpf);
            }
            if (name.equals("Right")) {
                body.applyForce(new Vector3f(-.5f, 0, 0), new Vector3f(.5f, .5f, 0));
                bulletAppState.update(tpf);
            }
            if (name.equals("Up")) {
                body.applyForce(new Vector3f(0, 0, .5f), new Vector3f(0, 0, 0));
                body2.applyForce(new Vector3f(0, 0, .5f), new Vector3f(0, 0, 0));
                bulletAppState.update(tpf);
            }
            if (name.equals("Down")) {
                body.applyForce(new Vector3f(0, 0, -.5f), new Vector3f(0, 0, 0));
                body2.applyForce(new Vector3f(0, 0, -.5f), new Vector3f(0, 0, 0));
                bulletAppState.update(tpf);
            }
        }
}
